package com.lagou.edu.sca.service;

import com.lagou.edu.users.pojo.LagouUser;
import com.lagou.edu.users.service.LagouUserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class JdbcUserDetailsService implements UserDetailsService {

    @Reference(retries = 0,check = true)
    private LagouUserService lagouUserService;

    @Override
    public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
        LagouUser lagouUser = lagouUserService.getLagouUserByEmail(email);
        if (lagouUser == null){
            throw new UsernameNotFoundException("用户不存在");
        }
        return new User(lagouUser.getEmail(),lagouUser.getPassword(),new ArrayList<>());
    }

}
